/*死亡之圈(数三退一)：

500个俘虏，围成一圈站
以某人为起点开始报数，

数到3的退出，一圈过后退出者被枪杀

然后继续，但是第一个人接刚才最后一个人报的数，而不是从1开始。

问最后剩下几个人？是第几个？*/

public class Deadcir{
	public static void main(String args[]){
		Doomedcir d = new Doomedcir(6, 3);
		d.startcount();
		d.result();
	}
}

class Doomedcir{
	int count;
	int number;
	Prisoner p[];

	Doomedcir(int x, int y){
		number = x;    count = y;
		p = new Prisoner[number];
		for (int i = 0; i < p.length; i++)
		{
			p[i] = new Prisoner();
			p[i].setid(i+1);
			
		}
	}

	void startcount(){
		int deadcount = 0; int currentcount = 0;
		while(deadcount < (number -1)){
			for (int i = 0; i < p.length; i++){
				if (p[i].getlive() == true){
					currentcount++;
					if (currentcount == count){
						p[i].setlive(false); deadcount++;
						currentcount = 0;
					}
				}
			}
		}
	}

	void result(){		
		for (int i = 0; i < number; i++){
			if(p[i].getlive() == true){ 
				System.out.println(p[i].getid()); }
		}
	}
}

class Prisoner{
	int id;
	boolean live = true;

	void setid(int x) { id = x; } 
	int getid() { return id; }
	void setlive(boolean x) { live = x; }
	boolean getlive() { return live; }

}




